    def vars_for_template(player):
        player.enter_time = time.time()                                                                                  ##newnew 1028
        objects = 0
        if player.subsession.treatment_name in C.TREATMENTS_1: objects = 1
        if player.subsession.treatment_name in C.TREATMENTS_2: objects = 2
        mechanisms = 0
        if player.subsession.treatment_name in C.TREATMENTS_O: mechanisms = 1
        if player.subsession.treatment_name in C.TREATMENTS_S: mechanisms = 2
        if player.subsession.treatment_name in C.TREATMENTS_A: mechanisms = 3                                            ##newnew 250224 AIODR1
        return dict(
            objects=objects,
            mechanisms=mechanisms,
            summary=get_summary_name(player),
        )



class MechanismWaitPage1(WaitPage):
    def after_all_players_arrive(group: Group):
        for player in group.get_players():
            if player.timed_out == 0:
                if player.subsession.treatment_name in C.TREATMENTS_M:
                    check_mutually_accepted_1(player)
                    calculate_payoffs_O1_O2_S1_S2(player)

            if player.subsession.treatment_name in C.TREATMENTS_A:                                                         ### newnew 250224 AIODR1
                total_submission = sum(
                    p.submission_1_objects_A for p in group.get_players()
                )
                if total_submission > 100:
                    player.group.predicted_outside_option1 = round(39.10685 + 0.1015475 * player.submission_1_objects_A
                                                     + 0.0047337 * player.submission_1_objects_A ** 2)                     ## newnew 20250224 AIODR1

            calculate_earnings(player)









def run_mechanism_1(player):
    match = player.group.get_player_by_id(player.player_matched)
    objects_A = player.subsession.objects_A
    submissions_sum = player.submission_1_objects_A + match.submission_1_objects_A
    # Check if matched player timed out
    if match.timed_out == 1:
        player.match_timed_out = 1
        if player.subsession.treatment_name in C.TREATMENTS_1:
            player.ecu_earned_this_round = player.outside_option_A
        if player.subsession.treatment_name in C.TREATMENTS_2:
            player.ecu_earned_this_round = player.outside_option_A + 50 * player.objects_B_multiplier
    else:
        # Check if the sum of both player submissions exceed the amount of objects A available
        if submissions_sum > objects_A:
            # If there are no second chances apply a breakdown
            if player.subsession.treatment_name in C.TREATMENTS_O:
                player.breakdown_happened = 1
            # If there are second chances enable the key
            if player.subsession.treatment_name in C.TREATMENTS_S:
                player.second_chance = 1
            # If AI will give suggestion before breakdown directly                                                         ## newnew 20250224 AIODR1
            if player.subsession.treatment_name in C.TREATMENTS_A:
                    player.group.predicted_outside_option1 = round(39.10685 + 0.1015475 * player.submission_1_objects_A
                                                     + 0.0047337 * player.submission_1_objects_A ** 2)                     ## newnew 20250224 AIODR1

        else:
            # Treatments with only objects A
            if player.subsession.treatment_name in C.TREATMENTS_1:
                # How many objects can subjects share
                remaining_objects = objects_A - submissions_sum
                player.suggestion_1_objects_A = player.submission_1_objects_A + remaining_objects / 2
            # Treatments with objects A and B
            if player.subsession.treatment_name in C.TREATMENTS_2:
                # If both subjects offered less than 50%
                if (player.submission_1_objects_A <= (objects_A / 2)) and (
                        match.submission_1_objects_A <= (objects_A / 2)):
                    player.suggestion_1_objects_A = objects_A / 2
                    player.suggestion_1_objects_B = objects_A / 2
                else:
                    if player.submission_1_objects_A > (objects_A / 2):
                        player.suggestion_1_objects_A = player.submission_1_objects_A
                        player.suggestion_1_objects_B = objects_A - player.submission_1_objects_A
                    if match.submission_1_objects_A > (objects_A / 2):
                        player.suggestion_1_objects_A = objects_A - match.submission_1_objects_A
                        player.suggestion_1_objects_B = match.submission_1_objects_A

